class Admin::CategoryController < ApplicationController  
  before_filter :login_required
  layout "admin"
  #around_filter :time_an_action
  
  #  def time_an_action
  #    started=Time.now
  #    yield
  #    elapsed=Time.now-started
  #    logger.info("#{action_name}耗时：#{elapsed}秒")
  #  end
  
  def index
    @categories=Category.paginate(:per_page=>10,:page=>params[:page])
  end
  
  def new
    @category=Category.new
  end
  
  def create
    @category=Category.new(params[:category])
    if @category.save
      flash[:notice]="["+@category.name+"]"+"保存成功！"
      redirect_to :action=>:index
    end
  end
  
  def delete
    @category=Category.find(params[:id])
    if @category.destroy
      redirect_to :action=>:index
    end
  end
  
  def edit
    @category=Category.find(params[:id])
  end
  
  def update
    category=Category.find(params[:id])
    if category.update_attributes(params[:category]) 
      redirect_to :action=>:index
    else
      redirect_to :action=>:edit
    end
  end
   
end  